[백준]단계별풀이_문자열


[백준] 단계별 - 문자열

11654번 - 아스키코드

https://www.acmicpc.net/problem/11654

import sys
print(ord(sys.stdin.readline().strip()))

11720번 - 숫자의 합

https://www.acmicpc.net/problem/11720

import sys
N = int(sys.stdin.readline())
cal = sys.stdin.readline()
ans = 0
for i in range(N):
    ans += int(cal[i])

print(ans)

10809번 - 알파벳 찾기

https://www.acmicpc.net/problem/10809

import sys

s = sys.stdin.readline().rstrip()
alphabet = list(range(97, 123))

for x in alphabet:
    print(s.find(chr(x)))

2675번 - 문자열 반복

https://www.acmicpc.net/problem/2675

import sys

n = int(sys.stdin.readline().strip())

for i in range(n):
    tmp = ''
    s = list(map(str, sys.stdin.readline().strip().split()))
    for j in s[1]:
        tmp += (j*int(s[0]))
    print(tmp)

1157번 - 단어 공부

https://www.acmicpc.net/problem/1157

import sys
from collections import Counter

s = sys.stdin.readline().strip()

arr = []
for i in s.upper():
    arr.append(i)

count = Counter(arr)
# print(count, count.most_common(1), count.most_common(2)[1])
try:
    if count.most_common(1)[0][1] == count.most_common(2)[1][1]:
        print("?")
    else:
        print(count.most_common(1)[0][0])
except:
    print(count.most_common(1)[0][0])

1152번 - 단어의 개수

https://www.acmicpc.net/problem/1152

import sys
s = sys.stdin.readline().rstrip().split()
print(len(s))

2908번 - 상수

https://www.acmicpc.net/problem/2908

import sys

a, b = sys.stdin.readline().rstrip().split()

tmp = int(a[::-1])
tmp2 = int(b[::-1])

arr = [tmp, tmp2]
print(max(arr))

5622번 - 다이얼

https://www.acmicpc.net/problem/5622

s = input().upper()

arr = ['ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQRS', 'TUV', 'WXYZ']
cnt = 0

for i in range(len(s)):
    for j in arr:
        if(s[i] in j):
            cnt += arr.index(j) + 3
print(cnt)

2941번 - 크로아티아 알파벳

https://www.acmicpc.net/problem/2941

a = ['c=', 'c-', 'dz=', 'd-', 'lj', 'nj', 's=', 'z=']
b = input()
for i in a:
    b = b.replace(i, 'a')
print(len(b))

1316번 - 그룹 단어 체커

https://www.acmicpc.net/problem/1316

# 내 풀이
# 처음에 나오는 단어들 pop해서 arr에 다 집어넣음
# 다른 단어가 최초로 들어왔을 때 set()으로 중복제거
# 그 이후에 들어오는 단어들이 arr에 있다면 그룹단어가 아님
# ex) "aabbcca" [a,a,b] => [a,b] => [a,b,b] => [a,b,c]

import sys

n = int(sys.stdin.readline().rstrip())
cnt = 0

for i in range(n):
    arr = []
    s = sys.stdin.readline().rstrip()

    for j in range(len(s) - 1):
        arr.append(s[j])
        if arr[-1] != s[j+1]:
            arr = list(set(arr))
            if s[j+1] in arr:
                break
    else:
        cnt += 1

print(cnt)

# 다른 사람 풀이
n = int(input())

group_word = 0
for _ in range(n):
    word = input()
    error = 0
    for index in range(len(word)-1):  # 인덱스 범위 생성 : 0부터 단어개수 -1까지
        if word[index] != word[index+1]:  # 연달은 두 문자가 다른 때,
            new_word = word[index+1:]  # 현재글자 이후 문자열을 새로운 단어로 생성
            if new_word.count(word[index]) > 0:  # 남은 문자열에서 현재글자가 있있다면
                error += 1  # error에 1씩 증가.
    if error == 0:
        group_word += 1  # error가 0이면 그룹단어
print(group_word)

위로 올라가기💨

Hello, I'm@nickhealthy
개발자를 꿈꾸고, 파이썬과 클라우드에 관심이 많은 비전공자

Github